package com.accp.crm.service;

import java.util.List;

import org.hibernate.SessionFactory;

import com.accp.crm.dao.CommonDAO;
import com.accp.crm.entity.CstActivity;

public class CstActivityService implements ICstActivity {
	
	private CommonDAO<CstActivity> cstActivitydao;
	
	public void setSessionFactory(SessionFactory sessionFactory){
		cstActivitydao = new CommonDAO<CstActivity>(sessionFactory,CstActivity.class);
	}

	@Override
	public void add(CstActivity cstactivity) {
		this.cstActivitydao.save(cstactivity);
	}

	@Override
	public void delete(Long id) {
		CstActivity cstactivity = this.cstActivitydao.findById(id);
		this.cstActivitydao.delete(cstactivity);

	}

	@Override
	public CstActivity findActivity(String custNo) {
		String hql = "from CstActivity c where c.cstCustomer=?";
		List list=this.cstActivitydao.findByHQL(hql, custNo);
		return (CstActivity) list.get(0);
	}
	public List findAll(String custNo) {
		String hql = "from CstActivity c where c.cstCustomer=?";
		return this.cstActivitydao.findByHQL(hql, custNo);
	}

	@Override
	public void update(CstActivity cstActivity) {
		this.cstActivitydao.update(cstActivity);

	}

	@Override
	public CstActivity findById(Long id) {
		return this.cstActivitydao.findById(id);
	}

}
